<template>
    <div class="app-teach">
        <div class="head">
            <el-avatar :size="120" :src="simg"></el-avatar>
            <p>{{sname}}</p>
        </div>
        <div class="body">
            <el-tabs v-model="activeTab" type="card" class="demo-tabs" @tab-click="handleClick">
                <el-tab-pane label="我的课程" name="first">
                    <ul>
              <li v-for="item in courses" :key="item.id">
                <RouterLink :to="`/courseintro/${item.id}`">
                <img :src=item.img />
                <div class="miaoshu dot">
                <span class="title ">{{ item.name }}</span>
                <div class="bottom">
                    <div class="count">
                        <p>{{item.studiedNumber}} 学习</p>
                        <p>
                        <i class="iconfont icon-zan"></i>
                        {{item.likeNumber}} 
                        </p>
                    </div>
                    <span class="datatime">{{dateFormat(item.createTime)}}</span>
                    <p class="depart">@达利不太圆 </p>
                </div>
                </div>
                </RouterLink>
           </li>          
        </ul>
      



                </el-tab-pane>
                <!-- <el-tab-pane label="我的测评" name="second">
                </el-tab-pane> -->
                
            </el-tabs>
        </div>
        
    </div>
</template>
<script setup>


import {onMounted, ref} from 'vue'
import { useRouter } from 'vue-router'
import {findUserAPI} from '@/apis/home'
import {findmyCourse} from '@/apis/course'


const courses = ref([])
const activeTab = ref('first')



const coursename = ref('')
const courseintro = ref('')
const courseid = ref('')



const sname = ref('')
const simg = ref('')
const getUserInfo = async () => {
    try { 
      
        const res = await findUserAPI();
        sname.value = res.data.data.name
        simg.value = res.data.data.avatar
       
        return res;
        
    } catch (error) {
        console.error(error);
    }
}
onMounted(()=>{
  getUserInfo(),
  getmyCourseList()
})

const router = useRouter()

const getmyCourseList = async()=>{
  const res = await findmyCourse()
  courses.value = res.data
  console.log(courses)
;
}


function dateFormat(time) {
      var date = new Date(time);
      var year = date.getFullYear();
      
      var month =
        date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
      var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    //   var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    //   var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    //   var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      // 拼接
      return year + "-" + month + "-" + day;
    }
</script>
<style scoped>
.app-teach {
    width: 1140px;
    margin: 0 auto;
    background-color: #fff;
}
.head{
    height: 200px;
    /* background-color: rgb(92,92,92); */
    margin-top: 20px;
    display: flex;
    padding: 20px 30px;
    align-items: center;
    /* border-bottom: 1px solid #000; */
}
.head p {
    /* color: #fff; */
    margin-left: 30px;
    font-size: 26px;
}
.body{
    padding: 20px 20px;
}
  table {
      border-collapse: collapse;
      width: 100%;
    }
    th, td {
      border: 1px solid black;
      padding: 8px;
      text-align: left;
    }
    th {
      background-color: #f2f2f2;
    }
    tr:nth-child(even) {
      background-color: #dddddd;
    }
    .form-group {
      margin-bottom: 10px;
    }
    .form-group label {
      display: block;
      font-weight: bold;
    }
    .form-group input[type="text"] {
      width: 300px;
    }
    .form-group input[type="submit"] {
      padding: 5px 10px;
      background-color: #4CAF50;
      color: white;
      border: none;
      cursor: pointer;
    }
.subBtn{
 margin-left: 180px;
}
#addbut{
  margin-top: 20px;

}

 ul{
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
   
}

ul li {
  box-shadow: 0px 0px 0px rgba(0,0,0,0.2);
  transition: box-shadow 0.3s;
  border:1px solid #EBEEF5;
}

ul li:hover {
  box-shadow: 3px 5px 10px rgba(0,0,0,0.3);
}
 ul li{
    list-style: none;
    width: 205px;
    height: 240px;
    margin-right: 18px;
      /* border: 1px solid #000; */
    background-color: #fff;
     border-radius: 5px;
     margin-bottom: 30px;
}
ul li:nth-child(5n){
    margin-right: 0;
}
li img{
    width: 100%;
    height: 120px;
     border-radius: 5px;

}
li .count{
    margin-top: 15px;
    display: flex;
    color:#999;
    /* margin-bottom: 5px; */
    font-size: 14px;
   
}
li .datatime {
    color:#999;
    font-size: 14px;
}
li .count p{
    margin-right: 20px;
}
li .miaoshu{
    padding: 0 10px;
}
li .depart{
    font-size: 14px;
    color:#ccc;

}
.dot {
    display: inline-block;
    width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>